package com.Renting.service.impl;

import com.Renting.dao.LoginDao;
import com.Renting.domain.RentingUser;
import com.Renting.service.ServiceLogin;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Service
public class ServiceLoginImpl implements ServiceLogin {

    @Resource
    LoginDao dao;

    //从dao层验证是否又对应的账号和密码，最终返回登录成功或失败
    public boolean ServiceIn(RentingUser user, HttpSession session) {
        RentingUser result =dao.LoginInDao(user);
        if(result!=null){
            session.setAttribute("Message",result);
            return true;
        }else{
            return false;
        }
    }

    //注册功能，进行数据库添加操作，简单判断是否注册成功
    @Override
    public void ServiceSignin(RentingUser user,HttpSession session) {
        int result= dao.SigninDao(user);
        if(result!=0){
            session.setAttribute("ErrorLogin","注册成功，请尝试登录！");
        }else{
            session.setAttribute("ErrorLogin","注册失败，请重试！");
        }
    }
}
